package com.globalwave.product.service;


import com.globalwave.base.BaseServiceImpl;
import com.globalwave.common.ArrayOrderList;
import com.globalwave.common.ArrayPageList;
import com.globalwave.product.entity.Product;
import com.globalwave.product.entity.ProductCriterion;

public class ProductServiceImpl 
       extends BaseServiceImpl 
       implements ProductService {

    public Product create(Product product) throws Exception {

    	//product.setCreated_on(U.currentTimestamp()) ;
    	
    	final Product result = (Product) jdbcDao.insert(product, true);
    	
    	return result ;
    }

    public void update(Product product) throws Exception {
    	product.addExclusions("created_on") ;
    	product.addExclusions("created_by") ;
    	//product.setUpdated_on(U.currentTimestamp()) ;
        jdbcDao.update(product) ;
    }

    public void delete(Product product) throws Exception {
        
        jdbcDao.delete(product) ;
        
    }

    public void deleteAll(Long[] ids) throws Exception {
    	ProductCriterion criterion = new ProductCriterion() ;
        criterion.setIds(ids) ;
        jdbcDao.delete(Product.class, criterion) ;
        
    }

    public ArrayPageList<Product> query(
    		ProductCriterion productCriterion, 
            int pageIndex, 
            int pageSize, 
            ArrayOrderList orderList) throws Exception {
        
        if (orderList == null) {
            orderList = new ArrayOrderList() ;
            orderList.addAsc("product_id") ;
        }
        
        return (ArrayPageList<Product>)jdbcDao.query(productCriterion, pageIndex, pageSize, orderList, Product.class);
    }


}
